package com.juhuacha.tryrxjava;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import java.util.ArrayList;
import java.util.List;

import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.functions.Func1;

public class ExoPlayer extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_exo_player);
         List<String> datas = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            datas.add("text" + (i+1));
        }
    /*    Observable.just("123")
                  .subscribeOn(AndroidSchedulers.mainThread())
                  .observeOn(AndroidSchedulers.mainThread())
                  .map(new Func1<String, List<String>>() {
                    @Override
                    public List<String> call(String text) {
                        List<String> datas = new ArrayList<>();
                        for (int i = 0; i < 10; i++) {
                            datas.add("text" + (i+1));
                        }
                        return datas;
                    }
                })
                  .flatMap(new Func1<List<String>,Observable<String>>() {
                      @Override
                      public Observable<String> call(List<String> strings) {
                          return Observable.from(strings);
                      }
                  })
                  .subscribe(new Action1<String>() {
                      @Override
                      public void call(String s) {
                        Log.i("array",s+"---");
                      }
                  });*/

        Observable.just(datas)
                  .subscribeOn(AndroidSchedulers.mainThread())
                  .observeOn(AndroidSchedulers.mainThread())
                  .flatMap(new Func1<List<String>, Observable<String>>() {
                      @Override
                      public Observable<String> call(List<String> strings) {
                          return Observable.from(strings);
                      }
                  })
                  .subscribe(new Action1<String>() {
                      @Override
                      public void call(String s) {
                          Log.i("array",s+"///");
                      }
                  });


        Observable.from(new Integer [] {1,2,3,4}).buffer(2).subscribe(new Subscriber<List<Integer>>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(List<Integer> integers) {
                Log.i("array",integers.size()+"-------");
            }
        });



    }
}
